﻿using System;
using System.Collections.Generic;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace kxjsj
{
    class PDFHelper
    {
        #region 生成列,需指定padding
        /// <summary>
        /// 生成列,需指定padding
        /// </summary>
        /// <param name="element"></param>
        /// <param name="paddingTop"></param>
        /// <param name="paddingRight"></param>
        /// <param name="paddingBottom"></param>
        /// <param name="paddingLeft"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element, float paddingTop, float paddingRight, float paddingBottom, float paddingLeft)
        {
            return CreateCell(element, paddingTop, paddingRight, paddingBottom, paddingLeft, 1, 1);
        }
        #endregion

        #region 生成列,需指定padding
        /// <summary>
        /// 生成列,需指定padding
        /// </summary>
        /// <param name="element"></param>
        /// <param name="paddingTop"></param>
        /// <param name="paddingRight"></param>
        /// <param name="paddingBottom"></param>
        /// <param name="paddingLeft"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element, float paddingTop, float paddingRight, float paddingBottom, float paddingLeft, int colspan)
        {
            PdfPCell cell = new PdfPCell();
            cell.AddElement(element);
            cell.PaddingTop = paddingTop;
            cell.PaddingRight = paddingRight;
            cell.PaddingBottom = paddingBottom;
            cell.PaddingLeft = paddingLeft;
            cell.Colspan = colspan;
            return cell;
        }
        #endregion

        #region 生成列,需指定padding
        /// <summary>
        /// 生成列,需指定padding
        /// </summary>
        /// <param name="element"></param>
        /// <param name="paddingTop"></param>
        /// <param name="paddingRight"></param>
        /// <param name="paddingBottom"></param>
        /// <param name="paddingLeft"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element, float paddingTop, float paddingRight, float paddingBottom, float paddingLeft, int colspan, int rowspan)
        {
            PdfPCell cell = new PdfPCell();
            cell.AddElement(element);
            cell.PaddingTop = paddingTop;
            cell.PaddingRight = paddingRight;
            cell.PaddingBottom = paddingBottom;
            cell.PaddingLeft = paddingLeft;
            cell.Colspan = colspan;
            cell.Rowspan = rowspan;
            return cell;
        }
        #endregion

        #region 生成列,需指定padding
        /// <summary>
        /// 生成列,需指定padding
        /// </summary>
        /// <param name="element"></param>
        /// <param name="paddingTop"></param>
        /// <param name="paddingRight"></param>
        /// <param name="paddingBottom"></param>
        /// <param name="paddingLeft"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(float paddingTop, float paddingRight, float paddingBottom, float paddingLeft, int colspan, int rowspan, params IElement[] element)
        {
            PdfPCell cell = new PdfPCell();
            cell.PaddingTop = paddingTop;
            cell.PaddingRight = paddingRight;
            cell.PaddingBottom = paddingBottom;
            cell.PaddingLeft = paddingLeft;
            cell.Colspan = colspan;
            cell.Rowspan = rowspan;
            foreach (IElement e in element)
            {
                cell.AddElement(e);
            }
            return cell;
        }
        #endregion

        #region 按默认padding生成列
        /// <summary>
        /// 按默认padding生成列
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element)
        {
            return CreateCell(element, 0, 0, 5, 3);
        }
        #endregion

        #region 按默认padding生成列
        /// <summary>
        /// 按默认padding生成列
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(params IElement[] element)
        {
            return CreateCell(0, 0, 5, 3, 1, 1, element);
        }
        #endregion

        #region 按默认padding生成列
        /// <summary>
        /// 按默认padding生成列
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element, int colspan)
        {
            return CreateCell(element, 0, 0, 5, 3, colspan);
        }
        #endregion

        #region 按默认padding生成列
        /// <summary>
        /// 按默认padding生成列
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static PdfPCell CreateCell(IElement element, int colspan, int rowspan)
        {
            return CreateCell(element, 0, 0, 5, 3, colspan, rowspan);
        }
        #endregion

        #region 设置cell的高度
        /// <summary>
        /// 设置cell的高度
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static PdfPCell SetHeight(PdfPCell cell, float height)
        {
            cell.FixedHeight = height;
            return cell;
        }
        #endregion
    }
}
